<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
	<script src="../node_modules/axios/dist/axios.js"></script>
</head>
<body>
<button>发送请求</button>
<button>取消请求</button>
</body>
<script type="module">
	// import axios from "./index.js";
	let cancelFn = null;
	const btns = document.querySelectorAll("button");
	btns[0].onclick = function () {
		if(cancelFn) cancelFn();
		axios.get("http://zhangpeiyue.com/scoreList", {
			cancelToken: new axios.CancelToken(function (cancel) {
				cancelFn = cancel;
			})
		}).catch(err=>{
			console.log(err)
		})
	}
	btns[1].onclick = function(){
		if(cancelFn) cancelFn();
	}
</script>
</html>